<?php

include_once './lib/facebook.php';

$facebook = new Facebook(array(
    'appId' => '523682457680450',
    'secret' => 'd6a793ffefb785f77f50461e5c4d01c7',
        ));
$user = $facebook->getUser();

//If the user is logged in their UID will be associated with the $user variable.
//Otherwise, it will be 0.
if ($user) {   
    $page_type = "RESTAURANT/CAFE";
    $my_friends = "SELECT uid2 FROM friend WHERE uid1 = $user";
    $liked_page_fans = "SELECT page_id FROM page_fan WHERE uid IN ($my_friends)";
    $page_query = "SELECT page_id, name, type, categories FROM page WHERE page_id IN ($liked_page_fans) and type = '$page_type'";
    $friendPageLikes = $facebook->api(array(
        'method' => 'fql.query',
        'query' => $page_query,
    ));
    $params = array('next' => 'http://localhost/obscure-spire-7574/logout.php');
    echo("$name is logged in.  Log out using <a href=" . $facebook->getLogoutUrl($params) . "> this link </a>");
//    echo '<ul>';
//    foreach ($friends["data"] as $value) { 
//        if ($friend_ids) {
//            $friend_ids = $friend_ids . "," . $value["id"];
//        } else {
//            $friend_ids = $value["id"];
//        }
//        echo '<li>';
//        echo '<div class="pic">';
//        echo '<img src="https://graph.facebook.com/' . $value["id"] . '/picture"/>';
//        echo '</div>';
//        echo '<div class="picName">' . $value["name"] . '</div>';
//        echo '</li>';
//    }
//    echo '</ul>';
//    $likes_string = "likes?ids=" . $friend_ids;
//    $likes = $facebook->api($likes_string);
//    var_dump($friend_ids);
//    var_dump($likes_string);
//    var_dump($likes);
    var_dump($friendPageLikes);
} else {
    echo("No user is currently logged in. Log in using <a href=" . $facebook->getLoginUrl() . "> this link </a>");
}